$(function(){
	var cookieName = $.cookie('username')
	if(cookieName){
//		onerror当文件加载失败时会触发这个事件
		var header = '<img src="uploads/' + $.cookie('header') + '" onerror="this.src=\'images/user.png\'">' 
		$('#user').empty().html(header + cookieName)
	}
	$('.dropdown-menu li').last().click(function(){
		$.removeCookie('username')
		location.reload()
	})
	
	$('#user').click(function(){
		if(!cookieName){
			$(this).removeAttr('data-toggle')
			location.href = '/login.html'
		}
	})
	
	$('form').submit(function(e){
		e.preventDefault()
		var data = new FormData(this)
		// console.log(data)
		$.post({
			url:'/header',
			data:data,
			contentType:false,
			processData:false,
			success:function(data){
				// console.log(data)
			}
		})
		
	})
})
